
enum HttpMethod { GET, POST, DELETE }

abstract class BaseRequest {
  var pathParams;
  var useHttps = true;

  String authority() {
    return 'www.wanandroid.com';
  }

  HttpMethod httpMethod();

  String path();

  String url() {
    Uri uri;
    var pathStr = path();
    if (pathParams != null) {
      if (path().endsWith("/")) {
        pathStr = "${path()}$pathParams";
      } else {
        pathStr = "${path()}/$pathParams";
      }
    }
    ///http和https的切换
    if (useHttps) {
      uri = Uri.https(authority(), pathStr, params);
    } else {
      uri = Uri.http(authority(), pathStr, params);
    }
    ///如果这个接口需要登录，那么必须携带登录返回的token
    // if(needLogin()){
    // addHeader("token", LoginDao.getBoardingPass);
    // }
    return uri.toString();
  }

  ///是否需要登录
  bool needLogin();

  ///参数集合
  Map<String, String> params = {};

  ///参数集合
  BaseRequest add(String k, Object v) {
    params[k] = v.toString();
    return this;
  }

  ///请求头
  Map<String, dynamic> header = {};

  BaseRequest addHeader(String k, Object v) {
    params[k] = v.toString();
    return this;
  }
}
